﻿''' <summary>
''' 需求：反應客服部處理的工作情況
''' </summary>
''' <remarks></remarks>
Public Class frm_CSPrintWeekInfoNew

    Implements IDServer.IDServer.IDServer


#Region "Variabled"

#Region "System Variabled Define"


    Public ActionHelp As IDServer.IDServer.ActionBtn = IDServer.IDServer.ActionBtn.ActionHelp

    Private WithEvents MainForm As Frm_MainForm

    Public Property SelectObject() As Frm_MainForm
        Get
            Return MainForm
        End Get
        Set(ByVal value As Frm_MainForm)
            MainForm = value
        End Set
    End Property

    Public action_help As IDServer.IDServer.ActionBtn = IDServer.IDServer.ActionBtn.ActionHelp

#End Region

#Region "user variabled define"

    ''' <summary>
    ''' 窗體是否加載
    ''' </summary>
    ''' <remarks></remarks>
    Private fLoadBool As Boolean = False

#End Region

#End Region

#Region "Methods"

    Private Function Return_PrintDataTable() As DataTable

        Dim sql As String = ""
        Dim spName As String = ""
        If Me.cbxType.Text.Equals("CS", StringComparison.InvariantCultureIgnoreCase) Then
            spName = "[usp_PrintWeekInfoNewCS]"
        ElseIf Me.cbxType.Text.Equals("<CS>", StringComparison.InvariantCultureIgnoreCase) Then
            spName = "[usp_PrintWeekInfoOld]"
        ElseIf Me.cbxType.Text.Equals("偉倫", StringComparison.InvariantCultureIgnoreCase) Then
            spName = "[usp_PrintWeekInfoNewWL]"
        End If
        sql = " Exec " + spName + "  '" & Format(Me.dtp_start_1.Value, "yyyy-MM-dd") & "','" & Format(Me.dtp_end_1.Value, "yyyy-MM-dd") & "'," & Val(Me.txtFax.Text.Trim) & "," & Val(Me.txtfFax_D.Text.Trim) & "," & Val(Me.txtfFax_S.Text.Trim) & "," & Val(Me.txtfFax_T.Text.Trim) & ",   " & _
                                                                " " & Val(Me.txtfEmail.Text.Trim) & "," & Val(Me.txtfEmail_D.Text.Trim) & "," & Val(Me.txtfEmail_S.Text.Trim) & "," & Val(Me.txtfEmail_T.Text.Trim) & "," & _
                                                                "'" & Me.txtfDept_1.Text.Trim & "','" & Me.txtfDept_2.Text.Trim & "','" & Me.txtfDept_3.Text.Trim & "'," & _
                                                                " " & Val(Me.txtfDept_amount_1.Text.Trim) & "," & Val(Me.txtfDept_amount_2.Text.Trim) & "," & Val(Me.txtfDept_amount_3.Text.Trim) & " "
        Dim Dtab As New DataTable
        Try
            Dtab = Exec(sql, E_ExecType.DataTable)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        Return Dtab
    End Function

#Region "AddHandler Events"

    ''' <summary>
    ''' KeyDown Event
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub TextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Try
            Select Case e.KeyCode
                Case Keys.Enter
                    If e.Shift = True Then
                        If TypeOf sender Is ComboBox Then
                            If CType(sender, ComboBox).DroppedDown = True Then
                                CType(sender, ComboBox).DroppedDown = False
                            End If
                        End If
                        Me.ProcessTabKey(False)
                        SendKeys.Send("{F4}")
                    Else
                        If sender.Name.ToString.IndexOf("Remark") <= 0 Then
                            If TypeOf sender Is ComboBox Then
                                If CType(sender, ComboBox).DroppedDown = True Then
                                    CType(sender, ComboBox).DroppedDown = False
                                End If
                            End If
                            Me.ProcessTabKey(True)
                            SendKeys.Send("{F4}")
                        End If
                    End If
            End Select
        Catch ex As Exception
            MsgBox("TextBox_KeyDown:" & ex.Message & ex.StackTrace, MsgBoxStyle.Critical And MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    ''' <summary>
    ''' 添加自定義事件
    ''' </summary>
    ''' <param name="Pans"></param>
    ''' <remarks></remarks>
    Private Sub AddHandlers(ByVal Pans() As Control)
        Try
            For Each Pan As Control In Pans
                For Each Ctrl As Control In Pan.Controls
                    If TypeOf Ctrl Is TextBox _
                       OrElse TypeOf Ctrl Is ComboBox _
                       OrElse TypeOf Ctrl Is DateTimePicker Then
                        AddHandler Ctrl.KeyDown, AddressOf TextBox_KeyDown
                    End If
                Next
            Next
        Catch ex As Exception
            MsgBox("AddHandlers:" & ex.Message & ex.StackTrace, MsgBoxStyle.Critical And MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

#End Region

#End Region

#Region "Events"

    Private Sub Frm_CSPrintWeekInfo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.fLoadBool = False
        Me.dtp_start_1.Text = ServerDate
        Me.dtp_end_1.Text = ServerDate
        Me.AddHandlers(New Control() {Me.Panel1})
        Dim imeMode As clsIme = New clsIme()
        imeMode.AddHandler_ImeMode(New Control() {Panel1})
        Me.cbxType.Items.Clear()
        Me.cbxType.Items.Add("<CS>")
        Me.cbxType.Items.Add("CS")
        Me.cbxType.Items.Add("偉倫")
        Me.cbxType.SelectedIndex = 0
        Me.fLoadBool = True
    End Sub

    Private Sub btnFind_1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind_1.Click
        Try
            Me.Cursor = Cursors.WaitCursor
            If Me.cbxType.SelectedIndex = -1 Or Me.cbxType.Text = "" Then
                Me.cbxType.Focus()
                Me.cbxType.DroppedDown = True
                Exit Sub
            End If
            Dim Dtab As DataTable = Me.Return_PrintDataTable()
            Dim filename As String = ""
            filename = GetReportPath("CS", "PrintWeekInfoNew.rpt")
            Dim myreport As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
            myreport.Load(filename, CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
            SetCrystalReportLoginfo(myreport)
            myreport.SetDataSource(Dtab)
            Dim TxtfEmployee As CrystalDecisions.CrystalReports.Engine.TextObject = myreport.ReportDefinition.ReportObjects("Text_fEmployee")
            Dim fRemark As CrystalDecisions.CrystalReports.Engine.TextObject = myreport.ReportDefinition.ReportObjects("Text_Message")
            TxtfEmployee.Text = PubUserName
            fRemark.Text = Me.txtfRemark.Text
            Dim textObjTitle As CrystalDecisions.CrystalReports.Engine.TextObject = myreport.ReportDefinition.ReportObjects("Text31")
            If Not String.IsNullOrEmpty(Me.cbxType.Text.Trim) Then
                textObjTitle.Text = textObjTitle.Text + "(" + Me.cbxType.Text + ")"
            End If
            Me.CrystalReportViewer1.ReportSource = myreport
        Catch ex As Exception
            MessageBox.Show(ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            Me.Cursor = Cursors.Default
        End Try
    End Sub

#End Region

#Region "Interface"

    Public Function ActionAdd() As Boolean Implements IDServer.IDServer.IDServer.ActionAdd

    End Function

    Public Function ActionCancel() As Boolean Implements IDServer.IDServer.IDServer.ActionCancel

    End Function

    Public Function ActionDelete() As Boolean Implements IDServer.IDServer.IDServer.ActionDelete

    End Function

    Public Function ActionEdit() As Boolean Implements IDServer.IDServer.IDServer.ActionEdit

    End Function

    Public Function ActionExport() As Boolean Implements IDServer.IDServer.IDServer.ActionExport

    End Function

    Public Function ActionFilter() As Boolean Implements IDServer.IDServer.IDServer.ActionFilter

    End Function

    Public Function ActionGoFirst() As Boolean Implements IDServer.IDServer.IDServer.ActionGoFirst

    End Function

    Public Function ActionGoLast() As Boolean Implements IDServer.IDServer.IDServer.ActionGoLast

    End Function

    Public Function ActionGoNext() As Boolean Implements IDServer.IDServer.IDServer.ActionGoNext

    End Function

    Public Function ActionGoPrevious() As Boolean Implements IDServer.IDServer.IDServer.ActionGoPrevious

    End Function

    Public Function ActionImport() As Boolean Implements IDServer.IDServer.IDServer.ActionImport

    End Function

    Public Function ActionInitialize() As Boolean Implements IDServer.IDServer.IDServer.ActionInitialize

    End Function

    Public Function ActionPrint() As Boolean Implements IDServer.IDServer.IDServer.ActionPrint

    End Function

    Public Function ActionSave() As Boolean Implements IDServer.IDServer.IDServer.ActionSave

    End Function

    Public Function ActionSelect() As Boolean Implements IDServer.IDServer.IDServer.ActionSelect

    End Function

#End Region

End Class
